CHARTS
Photo by Johny Goerend on Unsplash
A pile of rocks ceases to be a rock pile when somebody contemplates it with the idea of a cathedral in mind…
— Antoine Saint-Exupéry
# Load csv data file
url_root <- "https://raw.githubusercontent.com/UN-AVT/kamino-source/main/sources/0-shared/data/"
url_file1 <- "ideas-factories/gdp-per-person-employed-constant-ppp.csv"
url1 <- paste0(url_root, url_file1)
url_file2 <- "ideas-factories/global-innovation-index.csv"
url2 <- paste0(url_root, url_file2)
df_gdp<- read.csv(url1, header = TRUE, stringsAsFactors = FALSE)
df_gdp
df_gii<- read.csv(url2, header = TRUE, stringsAsFactors = FALSE)
df_gii
df_gdp_filtered <- df_gdp %>% filter(Year == 2020)
df_gii_filtered <- df_gii %>% filter(Indicator == 'Global Innovation Index')
df_gii_filtered <- df_gii_filtered %>% filter(Subindicator.Type == 'Rank')
df_gii_filtered <- df_gii_filtered %>% select(c(Country.ISO3, Country.Name, X2020))
df_combined <- merge(df_gdp_filtered, df_gii_filtered, by.x='Code', by.y='Country.ISO3')
df_combined$REGION <- countrycode(df_combined$Code, origin='iso3c', destination='un.region.name')
df_combined <- df_combined %>% select(c(Code, Entity, GDP.per.person.employed..constant.2017.PPP..., X2020, REGION))
df_combined <- df_combined[complete.cases(df_combined), ]
df_final <- df_combined %>%
rename(ISO3 = Code,
COUNTRY = Entity,
GDP = GDP.per.person.employed..constant.2017.PPP...,
GII = X2020)
df_final <- df_final %>% rename_with(toupper)
df_final
theme_opts <- theme(
text = element_text(family = "inconsolata", size = 16),
plot.title = element_text(color = "black", size = 16, face = "bold"),
plot.subtitle = element_text(color = "black", size = 12),
plot.caption = element_text(color = "#555555", size = 10),
# axis.title.x = element_blank(),
# axis.title.y = element_blank(),
# axis.text.x = element_text(vjust = 12),
panel.border = element_blank(),
panel.background = element_blank(),
# panel.grid.minor = element_blank(),
# panel.grid.major = element_blank(),
legend.position='top'
)
# Plot
v1 <- ggplot(df_final, aes(x = GDP, y = GII)) +
geom_point(aes( fill = REGION, color = REGION), size = 4, shape = 21) +
geom_smooth(formula = y ~ x, method="loess", se = FALSE, linetype = 'solid', size = 2, color = '#82A0C2') + # "lm", "glm", "gam", "loess"
scale_x_continuous() +
scale_y_continuous() +
scale_y_reverse() +
labs( title = "Ideas Factories",
subtitle = "Global Innovation and GDP",
caption = "Source: Cornell INSEAD WIPO",
x = "GDP per Person Employed, constant PPP, 2020",
y = "Global Innovation Index, 2020") +
theme_bw() +
theme_opts
girafe(ggobj = v1, width_svg = 16, height_svg = 12,
options = list(opts_sizing(rescale = TRUE, width = 0.75))
)
v2 <- v1 +
annotate("text", x = 200000, y = 30,
label = "European countries presented high GDP\ndespite the low Global Innovation Index",
hjust = "left", vjust = 1, color = "#333333", size = 4, fontface = 1) +
annotate("text", x = 45000, y = 110,
label = "African countries presented low GDP despite\nthe high Global Innovation Index",
hjust = "left", vjust = 1, color = "#333333", size = 4, fontface = 1)
girafe(ggobj = v2, width_svg = 16, height_svg = 12,
options = list(opts_sizing(rescale = TRUE, width = 0.75))
)